from PyQt5.QtSql import QSqlDatabase,QSqlQuery
 
 
def createDB():
    db=QSqlDatabase.addDatabase('QSQLITE')#指定数据库类型
    #指定SQLite数据库文件名
    db.setDatabaseName('./muttonDB.db')#muttonDB.db之前的目录都要存在才可建立成功！数据库名字自己随便起
    if not db.open():
        print('无法建立与数据库的连接')
        return False
    query=QSqlQuery()
    query.exec('create table people(id int primary key,name varcahr(10),address varcahr(50))')
    query.exec('insert into people values(1,"李宁","Shenyang")')
    query.exec('insert into people values(2,"超人","克星")')
    db.close()
    return True
 
 
if __name__=='__main__':
    createDB()
 
